﻿namespace Infra.Validation
{
    /// <summary>
    /// A "Easier" class for the validation process.
    /// </summary>
    public class ValidationEasier
    {
        /// <summary>
        /// Easier method to validate a rule set.
        /// </summary>
        /// <typeparam name="T">The type of the entity to validate.</typeparam>
        /// <param name="rulesSet">The validation rule set.</param>
        /// <param name="entityToValidate">The entity to validate.</param>
        /// <returns>A validation result containing the result of the validation.</returns>
        public static ValidationResult ValidateRuleSet<T>(RulesSet<T> rulesSet, T entityToValidate) where T : class
        {
            ValidationResult result =
                new ValidationEngineFor<T>(new RulesSetValidator<T>(rulesSet)).Validate(entityToValidate);

            return result;
        }

        /// <summary>
        /// Easier method to validate a single rule.
        /// </summary>
        /// <typeparam name="T">The type of the entity to validate.</typeparam>
        /// <param name="validationRule">The validation rule itself.</param>
        /// <param name="entityToValidate">The entity to validate.</param>
        /// <returns>A validation result containing the result of the validation.</returns>
        public static ValidationResult ValidateRule<T>(ValidationRuleFor<T> validationRule, T entityToValidate) where T : class
        {
            ValidationResult result =
                new ValidationEngineFor<T>(new SingleRuleValidator<T>(validationRule)).Validate(entityToValidate);

            return result;
        }
    }
}
